package com.lsw.joy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.security.Principal;

/**
 * @author Hasee
 * @date 2021/10/14
 */
@EnableSwagger2
@Configuration
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .ignoredParameterTypes(Principal.class)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/joy/**"))
                .build()
                .groupName("需要认证接口")
                .pathMapping("/")
                .apiInfo(apiInfo("需要认证接口文档"));

    }

    @Bean
    public Docket publicApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .ignoredParameterTypes(Principal.class)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/public/**"))
                .build()
                .groupName("不需要认证接口")
                .pathMapping("/")
                .apiInfo(apiInfo("不需要认证接口文档"));
    }

    private ApiInfo apiInfo(String description) {
        return new ApiInfoBuilder().title("laboratory接口文档").description(description).version("1.0").build();
    }

}
